home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / monitory / lav / aload.c < prev    next >
C/C++ Source or Header  |  1993-06-14  |  4KB  |  187 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : srn
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <clib/diskfont_protos.h>
  24.  
  25. #include "ALoad.h"
  26.  
  27. struct Screen         *Scr = NULL;
  28. UBYTE                 *PubScreenName = NULL;
  29. APTR                   VisualInfo = NULL;
  30. struct Window         *ALoadWnd = NULL;
  31. struct IntuiMessage    ALoadMsg;
  32. UWORD                  ALoadZoom[4];
  33. UWORD                  ALoadLeft = 574;
  34. UWORD                  ALoadTop = 12;
  35. UWORD                  ALoadWidth = 121;
  36. UWORD                  ALoadHeight = 72;
  37. UBYTE                 *ALoadWdt = (UBYTE *)"ALoad";
  38. struct TextAttr       *Font, Attr;
  39. UWORD                  FontX, FontY;
  40. UWORD                  OffX, OffY;
  41. struct TextFont       *ALoadFont = NULL;
  42.  
  43. static UWORD ComputeX( UWORD value )
  44. {
  45.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  46. }
  47.  
  48. static UWORD ComputeY( UWORD value )
  49. {
  50.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  51. }
  52.  
  53. static void ComputeFont( UWORD width, UWORD height )
  54. {
  55.     Forbid();
  56.     Font = &Attr;
  57.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  58.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  59.     FontX = GfxBase->DefaultFont->tf_XSize;
  60.     Permit();
  61.  
  62.     OffX = Scr->WBorLeft;
  63.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  64.  
  65.     if ( width && height ) {
  66.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  67.             goto UseTopaz;
  68.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  69.             goto UseTopaz;
  70.     }
  71.     return;
  72.  
  73. UseTopaz:
  74.     Font->ta_Name = (STRPTR)"topaz.font";
  75.     FontX = FontY = Font->ta_YSize = 8;
  76. }
  77.  
  78. int SetupScreen( void )
  79. {
  80.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  81.         return( 1L );
  82.  
  83.     ComputeFont( 0, 0 );
  84.  
  85.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  86.         return( 2L );
  87.  
  88.     return( 0L );
  89. }
  90.  
  91. void CloseDownScreen( void )
  92. {
  93.     if ( VisualInfo ) {
  94.         FreeVisualInfo( VisualInfo );
  95.         VisualInfo = NULL;
  96.     }
  97.  
  98.     if ( Scr        ) {
  99.         UnlockPubScreen( NULL, Scr );
  100.         Scr = NULL;
  101.     }
  102. }
  103.  
  104. int HandleALoadIDCMP( void )
  105. {
  106.     struct IntuiMessage    *m;
  107.     BOOL            running = TRUE;
  108.  
  109.     while( m = GT_GetIMsg( ALoadWnd->UserPort )) {
  110.  
  111.         CopyMem(( char * )m, ( char * )&ALoadMsg, (long)sizeof( struct IntuiMessage ));
  112.  
  113.         GT_ReplyIMsg( m );
  114.  
  115.         switch ( ALoadMsg.Class ) {
  116.  
  117.             case    IDCMP_REFRESHWINDOW:
  118.                 GT_BeginRefresh( ALoadWnd );
  119.                 GT_EndRefresh( ALoadWnd, TRUE );
  120.                 break;
  121.  
  122.             case    IDCMP_CLOSEWINDOW:
  123.                 running = ALoadCloseWindow();
  124.                 break;
  125.  
  126.                 break;
  127.         }
  128.     }
  129.     return( running );
  130. }
  131.  
  132. int OpenALoadWindow( void )
  133. {
  134.     UWORD        wleft = ALoadLeft, wtop = ALoadTop, ww, wh;
  135.  
  136.     ComputeFont( ALoadWidth, ALoadHeight );
  137.  
  138.     ww = ComputeX( ALoadWidth );
  139.     wh = ComputeY( ALoadHeight );
  140.  
  141.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  142.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  143.  
  144.     if ( ! ( ALoadFont = OpenDiskFont( Font )))
  145.         return( 5L );
  146.  
  147.     ALoadZoom[0] = ALoadLeft;
  148.     ALoadZoom[1] = ALoadTop;
  149.     if ( ALoadWdt )
  150.         ALoadZoom[2] = TextLength( &Scr->RastPort, (UBYTE *)ALoadWdt, strlen((char *)ALoadWdt )) + 80;
  151.     else
  152.         ALoadZoom[2]  = 80L;
  153.         ALoadZoom[3] = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  154.  
  155.     if ( ! ( ALoadWnd = OpenWindowTags( NULL,
  156.                 WA_Left,    wleft,
  157.                 WA_Top,        wtop,
  158.                 WA_Width,    ww + OffX + Scr->WBorRight,
  159.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  160.                 WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
  161.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
  162.                 WA_Title,    ALoadWdt,
  163.                 WA_ScreenTitle,    "ALoad V1.0 Copyright 1993 Stephen Norris",
  164.                 WA_PubScreen,    Scr,
  165.                 WA_Zoom,    ALoadZoom,
  166.                 TAG_DONE )))
  167.     return( 4L );
  168.  
  169.     GT_RefreshWindow( ALoadWnd, NULL );
  170.  
  171.     return( 0L );
  172. }
  173.  
  174. void CloseALoadWindow( void )
  175. {
  176.     if ( ALoadWnd        ) {
  177.         CloseWindow( ALoadWnd );
  178.         ALoadWnd = NULL;
  179.     }
  180.  
  181.     if ( ALoadFont ) {
  182.         CloseFont( ALoadFont );
  183.         ALoadFont = NULL;
  184.     }
  185. }
  186.  
  187.